{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Anaconda用法\n",
    "# Anaconda下载地址：https://www.anaconda.com/download/\n",
    "# Miniconda下载地址：https://docs.conda.io/en/latest/miniconda.html\n",
    "# 清华大学的conda源：https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/\n",
    "# Linux下安装是执行shell脚本，不懂的就一路回车，碰到yes或no就选yes即可，能看懂的就看着提示选择安装目录，是否自动激活环境。\n",
    "# Windows是可执行文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# windows下创建conda配置文件,linux下会自动创建无需手动创建\n",
    "conda config --set show_channel_urls yes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 设置清华大学的conda源，将下面内容追加到conda配置文件，默认在用户根目录下.condarc文件\n",
    "channels:\n",
    "  - defaults\n",
    "show_channel_urls: true\n",
    "default_channels:\n",
    "  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main\n",
    "  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r\n",
    "  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2\n",
    "custom_channels:\n",
    "  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud\n",
    "  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud\n",
    "  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud\n",
    "  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud\n",
    "  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud\n",
    "  pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud\n",
    "  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 清除索引缓存\n",
    "conda clean -i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 查看conda版本\n",
    "conda --version \n",
    "\n",
    "# 更新conda\n",
    "conda update conda\n",
    "\n",
    "# 显示conda安装的信息\n",
    "conda info -a #显示所有信息\n",
    "conda info -e #列出所有conda环境"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# linux下激活conda环境，base环境是conda安装后自带的\n",
    "# conda 4.6以前版本\n",
    "conda activate base\n",
    "\n",
    "# conda 4.6或更高版本\n",
    "source activate base\n",
    "\n",
    "# 停用conda环境，可以指定环境名，也可以不指定\n",
    "conda deactivate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 创建一个名为envname的虚拟环境，并安装python=3.6\n",
    "conda create --name envname python=3.6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 取消自动激活conda环境\n",
    "conda config --set auto_activate_base false"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 在conda环境中运行可执行文件，一下命令将输出envname环境的python版本\n",
    "conda run --name envname python --version"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 在conda环境中安装包，虚拟环境名称可以不用指定\n",
    "conda install --name envname package1 package2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 在conda环境中卸载包，remove和uninstall效果一样\n",
    "conda remove --name envname package1 package2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 查询conda包，可以不输入完整的包名\n",
    "conda search packagename\n",
    "\n",
    "# 查询指定conda包的可用版本\n",
    "conda search packagename=="
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 列出conda包\n",
    "conda list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 更新conda包\n",
    "conda update --name envname package1 package2"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Bash",
   "language": "bash",
   "name": "bash"
  },
  "language_info": {
   "codemirror_mode": "shell",
   "file_extension": ".sh",
   "mimetype": "text/x-sh",
   "name": "bash"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
